<?php
require_once APP . '/application/controllers/FrontAction.php';
require_once APP . '/application/models/Publication.php';

/**
 * 首页
 */
class PublicationController extends FrontAction
{
    public function init()
    {
    	$this->view->hmenu = 'publication';
    }
    /**
     * 首页
     *
     */
    public function indexAction()
    {
    	
    }
    
    public function listAction()
    {
    	$nowp = intval($this->getParam("nowp", 1));
    	$typeid =(int) $this->getParam("typeid", 0);
    	
    	$obj_list = new Alllist($this->db);
    	
    	if (empty($typeid)){// 默认取第一个分类
    		$typeid = $obj_list->getFirstListTypeId($this->cfg['listtype']['publication']);
    	}
    	
    	$obj_pub = new Publication($this->db);
    	$result = $obj_pub->listPublicationByWhere("where typeid=" . $typeid, $nowp, 12);
    	
    	$this->view->list = $result['list'];
    	$this->view->page = $result['page'];
    	$this->view->pagenum = Util::pageNumStyle($result['page']);

    	$this->view->typeid = $typeid;
    	$this->view->htitle = $this->cfg['lang']['index_pub'];
    	$this->view->types = $obj_list->getAllListByType($this->cfg['listtype']['publication'], false);
    	
    	$this->render("list");
    }
    
    
    public function detailAction()
    {
    	$pid = (int)$this->getParam("pid");
    	
    	$obj_list = new Alllist($this->db);    	
    	
    	$obj_pub = new Publication($this->db);
    	$content = $obj_pub->show($pid);
    	
    	$this->view->content = $content;
    	$this->view->htitle = htmlspecialchars($content['name']);
    	$this->view->types = $obj_list->getAllListByType($this->cfg['listtype']['publication'], false);
    	$this->view->currenttype = $this->view->types[$content['typeid']];
    	$this->view->typeid = $content['typeid'];
    	
    	$this->render("detail");
    }
    
}
